package com.algorithm.TwoMachine;

public class TwoMachine {
    public static int N=3;
    public static int M=2;
    public static int[][] help=new int[N][M];

    public static void swap(Task[] tasks,int i,int j){
        Task task=new Task(tasks[i]);
        tasks[i]=tasks[j];
        tasks[j]=task;
    }

    public static void calculate(Task[] tasks){
        help[0][0]=tasks[0].firstTime;
        help[0][1]=help[0][0]+tasks[0].secondTime;
        //计算出每个物品在机器一上加工完成的时间
        for(int i=1;i<N;i++){
            help[i][0]=help[i-1][0]+tasks[i].firstTime;
        }

        for(int i=1;i<N;i++){
            if(help[i][0]>help[i-1][1]){
                help[i][1]=help[i][0]+tasks[i].secondTime;
            }else{
                help[i][1]=help[i-1][1]+tasks[i].secondTime;
            }
        }
        System.out.println(help[N-1][1]);
    }

    public static void Try(Task[] tasks,int i){
        if(i>=N){
            for(int k=0;k<N;k++){
                System.out.println(tasks[k].firstTime+" "+tasks[k].secondTime);
            }
            calculate(tasks);
            System.out.println();
        }else {
            for(int j=i;j<N;j++){
                swap(tasks,i,j);
                Try(tasks,i+1);
                swap(tasks,i,j);
            }
        }
    }

    public static void main(String[] args) {

        Task[] tasks=new Task[N];
        for(int i=0;i<N;i++){
            tasks[i]=new Task();
        }
        //初始化tasks
        {
            tasks[0].firstTime=2;
            tasks[0].secondTime=1;
            tasks[1].firstTime=3;
            tasks[1].secondTime=1;
            tasks[2].firstTime=2;
            tasks[2].secondTime=3;
        }


        //对help数组初始化
        for(int i=0;i<N;i++){
            for(int j=0;j<M;j++){
                help[i][j]=0;
            }
        }

        //输出tasks的全排列
        Try(tasks,0);

    }
}
